import { useNavigate, useLocation } from "react-router-dom";
import { Outlet } from "react-router-dom";
import { useEffect } from "react";
import { message } from "antd";
const RouterBeforeEach = () => {
  const navigate = useNavigate();
  const location = useLocation();
  const noLoginUrl = [ 
    "/login",
  ]
  useEffect(() => {
    const isLogin = localStorage.getItem('token');
    console.log(isLogin);
    if (isLogin == null){
      if (noLoginUrl.indexOf(location.pathname) === -1) {
        message.warning("请先登录");
        navigate("/login");
        return
      }
    }
  }, [location.pathname]);
  return <Outlet />;
};

export default RouterBeforeEach;